let table_name = "banner_table";
let table_data_url = "/sys/banner/list";
let number_list = "<'row'<'#mytool.col-xs-3'><'col-xs-9'>><'row'<'.col-xs-12'tr>><'row'<'#num_menu.col-xs-2'l><'col-xs-10'p>>";

function action_status() {
}

let dataManage = {
    currentItem: null,
    fuzzySearch: true,
    getQueryCondition: function (data) {
        let param = {};
        param.start = data.start;
        param.length = data.length;
        return JSON.stringify(param);
    },
};

let returnData = {
    getDate: [
        {
            className: "ellipsis",
            data: "",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "title",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "status",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "image",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                if (isNotNull(row.image)) {
                    return '<img alt="" src="http://img.shengongying.cn/' + row.image + '" width="200px" height="200px">';
                }
            }
        }, {
            className: "ellipsis",
            data: "url",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "wight",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "content",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                let button = '';
                button += '<button class="btn btn-sm btn-success" onclick=banner_detail(' + row.id + ')>修改</button>';
                return button;
            }
        }
    ]
}

function foot_info(result) {
}

function createdRow(row, data, index) {
    if (data.role) {
        $(row).addClass("info");
    }
}

function drawCallback(settings) {
}

function search_user() {
    find();
}

function fn_draw_call_back() {
}

function create_banner(id) {
    $('#banner_id').val(id);
    $('#banner_modal').modal('show');
}

function banner_detail(id) {
    $('#banner_id').val(id);
    HttpUtils.post_json("/sys/banner/detail", JSON.stringify({"id": id}), function (result) {
        let data = result.data;
        $('#title').val(data.title);
        $('#status').val(data.status);
        $('#url').val(data.url);
        $('#_content').val(data.content);
        $('#wight').val(data.wight);
        init_image_item("http://img.shengongying.cn/"+data.image)
        $('#banner_modal').modal('show');
    });
}

modalClose('banner_modal', function () {
    $('#banner_id').val('');
    $('#title').val('');
    $('#status').val('');
    $('#url').val('');
    $('#_content').val('');
    $('#wight').val('');
    $('#image').val('');
    image_item_re_init()
});

function send_banner() {
    let formData = new FormData();

    let id = $('#banner_id').val();
    formData.append("id", id);

    let title = $('#title').val();
    formData.append("title", title);

    let status = $('#status').val();
    formData.append("status", status);

    let url = $('#url').val();
    formData.append("url", url);

    let content = $('#_content').val();
    formData.append("content", content);

    let wight = $('#wight').val();
    formData.append("wight", wight);

    let picture = $('#image')[0].files[0];
    formData.append("image", picture);


   HttpUtils.upload_file('/sys/file/save',formData,function (data) {
       $('#banner_modal').modal('hide');
       find();
   })
}